/*    */ package blockbuster.components.shape;
/*    */ 
/*    */ import blockbuster.components.BedrockComponentBase;
/*    */ import blockbuster.emitter.BedrockEmitter;
/*    */ import blockbuster.emitter.BedrockParticle;
/*    */ import blockbuster.math.molang.MolangException;
/*    */ import blockbuster.math.molang.MolangParser;
/*    */ import blockbuster.math.molang.expressions.MolangExpression;
/*    */ import com.google.gson.JsonArray;
/*    */ import com.google.gson.JsonElement;
/*    */ import com.google.gson.JsonObject;
/*    */ 
/*    */ public class BedrockComponentShapeBox
/*    */   extends BedrockComponentShapeBase {
/* 15 */   public MolangExpression[] halfDimensions = new MolangExpression[] { MolangParser.ZERO, MolangParser.ZERO, MolangParser.ZERO };
/*    */ 
/*    */   
/*    */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/* 19 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*    */     
/* 21 */     JsonObject element = elem.getAsJsonObject();
/*    */     
/* 23 */     if (element.has("half_dimensions")) {
/*    */       
/* 25 */       JsonArray array = element.getAsJsonArray("half_dimensions");
/*    */       
/* 27 */       if (array.size() >= 3) {
/*    */         
/* 29 */         this.halfDimensions[0] = parser.parseJson(array.get(0));
/* 30 */         this.halfDimensions[1] = parser.parseJson(array.get(1));
/* 31 */         this.halfDimensions[2] = parser.parseJson(array.get(2));
/*    */       } 
/*    */     } 
/*    */     
/* 35 */     return super.fromJson((JsonElement)element, parser);
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public JsonElement toJson() {
/* 41 */     JsonObject object = (JsonObject)super.toJson();
/* 42 */     JsonArray array = new JsonArray();
/*    */     
/* 44 */     for (MolangExpression expression : this.halfDimensions)
/*    */     {
/* 46 */       array.add(expression.toJson());
/*    */     }
/*    */     
/* 49 */     object.add("half_dimensions", (JsonElement)array);
/*    */     
/* 51 */     return (JsonElement)object;
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public void apply(BedrockEmitter emitter, BedrockParticle particle) {
/* 57 */     float centerX = (float)this.offset[0].get();
/* 58 */     float centerY = (float)this.offset[1].get();
/* 59 */     float centerZ = (float)this.offset[2].get();
/*    */     
/* 61 */     float w = (float)this.halfDimensions[0].get();
/* 62 */     float h = (float)this.halfDimensions[1].get();
/* 63 */     float d = (float)this.halfDimensions[2].get();
/*    */     
/* 65 */     particle.position.x = (centerX + ((float)Math.random() * 2.0F - 1.0F) * w);
/* 66 */     particle.position.y = (centerY + ((float)Math.random() * 2.0F - 1.0F) * h);
/* 67 */     particle.position.z = (centerZ + ((float)Math.random() * 2.0F - 1.0F) * d);
/*    */     
/* 69 */     if (this.surface) {
/*    */       
/* 71 */       int roll = (int)(Math.random() * 6.0D * 100.0D) % 6;
/*    */       
/* 73 */       if (roll == 0) { particle.position.x = (centerX + w); }
/* 74 */       else if (roll == 1) { particle.position.x = (centerX - w); }
/* 75 */       else if (roll == 2) { particle.position.y = (centerY + h); }
/* 76 */       else if (roll == 3) { particle.position.y = (centerY - h); }
/* 77 */       else if (roll == 4) { particle.position.z = (centerZ + d); }
/* 78 */       else if (roll == 5) { particle.position.z = (centerZ - d); }
/*    */     
/*    */     } 
/* 81 */     this.direction.applyDirection(particle, centerX, centerY, centerZ);
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\shape\BedrockComponentShapeBox.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */